home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / demos / GL / flight / fog.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  1.7 KB  |  81 lines

  1. /*
  2.  * Copyright 1989, 1990, 1991, 1992, 1993, 1994, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17.  
  18. /*
  19.  *  flight/fog.c $Revision: 1.2 $
  20.  */
  21.  
  22. #include "math.h"
  23. #include "fcntl.h"
  24. #include "stdio.h"
  25. #include "flight.h"
  26.  
  27.  
  28. #define MIN_FD        1
  29. #define START_FD    67
  30. #define MAX_FD        100
  31.  
  32.  
  33. int fogon = FALSE;
  34. int fog_d = START_FD;
  35. unsigned long fog_c = 0xff999999;
  36.  
  37.  
  38. set_fog_density(d)
  39.     int d;
  40. {
  41.     float p[4];
  42.  
  43.     fog_d += d;
  44.     if (fog_d < MIN_FD)
  45.     fog_d = MIN_FD;
  46.     else if (fog_d > MAX_FD)
  47.     fog_d = MAX_FD;
  48.  
  49.     p[0] = 1.0 / fexp(fog_d/6.0);
  50.     p[1] = (fog_c & 0xff) / 255.0;
  51.     p[2] = ((fog_c >> 8) & 0xff) / 255.0;
  52.     p[3] = ((fog_c >> 16) & 0xff) / 255.0;
  53.  
  54.     fogvertex(FG_DEFINE, p);
  55. }
  56.  
  57.  
  58. set_fog_color(c)
  59.     unsigned long c;
  60. {
  61.     float p[4];
  62.  
  63.     fog_c = c;
  64.     p[0] = 1.0 / fexp(fog_d/6.0);
  65.     p[1] = (fog_c & 0xff) / 255.0;
  66.     p[2] = ((fog_c >> 8) & 0xff) / 255.0;
  67.     p[3] = ((fog_c >> 16) & 0xff) / 255.0;
  68.  
  69.     fogvertex(FG_DEFINE, p);
  70. }
  71.  
  72.  
  73. fog(b)
  74. {
  75.     if (fogon = b)
  76.     fogvertex(FG_ON, (float *)0);
  77.     else
  78.     fogvertex(FG_OFF, (float *)0);
  79. }
  80.  
  81.